<?php
namespace app\home\controller;

use app\base\controller\BaseController;

/**
 * 前台公共类
 */
class HomeController extends BaseController {

    protected $crumbList = array();
    protected $metaTitle;
    protected $metaKeywords;
    protected $metaDescription;

    public function __construct() {
        parent::__construct();
    }

    /**
     * 前台模板显示 调用内置的模板引擎显示方法，
     * @access protected
     * @param string $tpl 指定要调用的模板文件
     * @return void
     */
    protected function homeDisplay($tpl = '') {
        //复制当前URL
        $this->assign('crumbList', $this->getCrumb());
        $this->assign('meta', $this->getMeta());
        if (empty($tpl)) {
            $tpl = ACTION_NAME;
        }
        $tpl = 'theme/' . config('TPL.TPL_THEME') . '/' . strtolower(APP_NAME) . '_' . strtolower(CONTROLLER_NAME) . '_' . strtolower($tpl);
        $this->resources = array();
        $this->display($tpl);

    }

    /**
     * 页面Meda信息组合
     * @return array
     */
    protected function getMeta() {
        return array(
            'title' => $this->metaTitle,
            'keywords' => $this->metaKeywords,
            'description' => $this->metaDescription,
        );
    }

    /**
     * 位置导航
     * @return array
     */
    protected function getCrumb() {
        return array_merge(
            array(
                'name' => '首页',
                'url' => __ROOT__,
            ),
            (array)$this->crumbList
        );
    }

    //分页结果显示
    protected function getPageShow($map = array()) {
        $pageArray = $this->pager;
        if ($pageArray['totalPage'] == 1) {
            return;
        }
        $html = '
        <div class="dux-page">
          <a class="first pageprv" href="' . $this->createPageUrl($map, $pageArray['firstPage']) . '">' . lang('first_page') . '</a>
          <a class="first pageprv" href="' . $this->createPageUrl($map, $pageArray['prevPage']) . '"><span class="pagearr">&lt;</span> ' . lang('pre_page') . '</a> ';
        foreach ($pageArray['allPages'] as $value) {
            if ($value == 0) {
                continue;
            }
            if ($value == $pageArray['page']) {
                $html .= '<a class="z-crt"';
            } else {
                $html .= '<a ';
            }
            $html .= ' href="' . $this->createPageUrl($map, $value) . '">' . $value . '</a>';
        }
        $html .= '<a class="last pagenxt" href="' . $this->createPageUrl($map, $pageArray['nextPage']) . '">' . lang('next_page') . '<span class="pagearr">&gt;</span></a>
          <a class="last-page" href="' . $this->createPageUrl($map, $pageArray['lastPage']) . '">' . lang('last_page') . '</a>
        </div>';
        return $html;

    }
}
